
Ext.onReady(function(){
			windowst.show();
			FenYe(0);
		});

		
		function FenYe(page){
			grids.getStore().removeAll();
			Ext.Ajax.request({
				url : "http://localhost:8080/querylyh",
				params :{page:page},
				method : "post",
				success : function(response) {
					
					pageBean=Ext.JSON.decode(response.responseText,true);
					//alert(JSON.stringify(pageBean));
					var datas=pageBean.data;
					//alert(JSON.stringify(datas));
					pb=datas;
					
					forms.getForm().setValues(Ext.decode(response.responseText).data[0]);
					grids.getStore().add(Ext.decode(response.responseText).data[0].allo);
					
					forms.getForm.reset();
				},
			});
		}

		var toolbar=Ext.create('Ext.toolbar.Toolbar',{
			renderTo:document.body,
			width:608,
			items:[
			       {text:'上一页',handler:function(){FenYe(pageBean.prevPage);}},
			       {text:'下一页',handler:function(){FenYe(pageBean.nextPage);}},
			       {text:'保存',handler:function(){add();}},
			       {text:'新增',handler:function(){XinZeng();}},
			       {text:'修改',handler:function(){add();}},
			       {text:'删除',handler:function(){update();}},
			       {text:'刷新',handler:function(){ShuaXin();}},
			       {xtype:'tbspacer',width:190},
			       {text:'审核',handler:function(){ShenHe();}},
			       {text:'反审核',handler:function(){FanShenHe();}}
			       ],
		});
		
		//新增
		function XinZeng(){
			danhao();
			Ext.getCmp('wareOutName').setValue("");
			Ext.getCmp('wareName').setValue("");
			Ext.getCmp('moveNo').setValue("");
			Ext.getCmp('makerSign').setValue("");
			Ext.getCmp('permitterSign').setValue("");
			Ext.getCmp('isDel').setValue("");
			Ext.getCmp('isShenHe').setValue("");
			Ext.pluck(grids.getStore().removeAll());
			
			
		}
		
		/**
		 * 单号
		 * @returns
		 */
		function danhao(){
			Ext.Ajax.request({
				url:"http://localhost:8080/lyhdanhao",
				params:{moveNo:Ext.getCmp('moveDate').getValue()},
				success:function(response){
					Ext.getCmp('moveNo').setValue(response.responseText);
				}
			});
		}
		
		function ShuaXin(){
			windowst.show();
		}
		//反审核
		function FanShenHe(){
				var rowCount=grids.getStore().getCount();
	        	var view=grids.getView();
	        	
	        	//调出仓库
	        	var wareOutName =Ext.getCmp('wareOutName').getValue();
	        	//调入仓库
	        	var wareName = Ext.getCmp('wareName').getValue();
	        	//alert(wareOutName);
	        	//alert(wareName);
	        	var moveNo = Ext.getCmp('moveNo').getValue();

	        	var quantity = 0;
	        	for (var i=0;i<rowCount;i++){
	        	 var data = grids.getStore().getAt(i).data;
	        	 //quantity=data.quantity;
	        	 quantity=data.quantity;
	        	}	        
	        	alert(quantity);
				Ext.Ajax.request({
					url:'http://localhost:8080/updateDepotDetaillyh',
					//headers:{"Content-Type":"application/json"},
					params:{shuliang:quantity,wareHouseID:wareName},
					success:function(response){
						Ext.MessageBox.alert("提示","审核成功",function(){});
					}
				});
				
				Ext.Ajax.request({
					url:'http://localhost:8080/updateDepotDetaillyh1',
					//headers:{"Content-Type":"application/json"},
					params:{shuliang:quantity,wareHouseID:wareOutName},
					success:function(response){
						//Ext.MessageBox.alert("提示","审核成功",function(){});
					}
				});
				
				Ext.Ajax.request({
					url:'http://localhost:8080/updateShenHeStuats',
					params:{moveNo:moveNo,isShenHe:'未审核'},
					success:function(response){
						//Ext.MessageBox.alert("提示","审核成功",function(){});
					}
				});
	        	
		}
		
		//审核
		function ShenHe(){
			var rowCount=grids.getStore().getCount();
			//alert(rowCount);
        	//var cc=cm1.getColumnCount();
        	var view=grids.getView();
        	//alert(view);
        	
        	//调出仓库
        	var wareOutName =Ext.getCmp('wareOutName').getValue();
        	//调入仓库
        	var wareName = Ext.getCmp('wareName').getValue();
        	//alert(wareOutName);
        	//alert(wareName);
        	var moveNo = Ext.getCmp('moveNo').getValue();
        	//alert(moveNo);
        	var quantity = 0;
        	for (var i=0;i<rowCount;i++){
        	 var data = grids.getStore().getAt(i).data;
        	 //quantity=data.quantity;
        	 quantity=data.quantity;
        	}	        
        	alert(quantity);
			Ext.Ajax.request({
				url:'http://localhost:8080/updateDepotDetaillyh',
				//headers:{"Content-Type":"application/json"},
				params:{shuliang:quantity,wareHouseID:wareOutName},
				success:function(response){
					Ext.MessageBox.alert("提示","审核成功",function(){});
				}
			});
			
			Ext.Ajax.request({
				url:'http://localhost:8080/updateDepotDetaillyh1',
				//headers:{"Content-Type":"application/json"},
				params:{shuliang:quantity,wareHouseID:wareName},
				success:function(response){
					//Ext.MessageBox.alert("提示","审核成功",function(){});
				}
			});
			
			Ext.Ajax.request({
				url:'http://localhost:8080/updateShenHeStuats',
				params:{moveNo:moveNo,isShenHe:'已审核'},
				success:function(response){
					//Ext.MessageBox.alert("提示","审核成功",function(){});
				}
			});
        	
		}
		
//		// 查询
//		Ext.Ajax.request({
//			// 被用来向服务器发起请求默认的url
//			url : "http://localhost:8080/querylyh",
//			// 请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串
//			params : [ {} ],
//			// 请求时使用的默认的http方法
//			method : "post",
//			// 请求成功时回调函数
//			success : function(data) {
//				var cate=JSON.parse(data.responseText);
//				var catee=cate[0].allo;
//				//alert(cate[0].isDel);
//				Ext.getCmp('wareOutName').setValue(cate[0].wareOutName);
//				Ext.getCmp('moveDate').setValue(cate[0].moveDate);
//				Ext.getCmp('wareName').setValue(cate[0].wareName);
//				Ext.getCmp('moveNo').setValue(cate[0].moveNo);
//				Ext.getCmp('makerSign').setValue(cate[0].makerSign);
//				Ext.getCmp('permitterSign').setValue(cate[0].permitterSign);
//				Ext.getCmp('isDel').setValue(cate[0].isDel);
//				Ext.getCmp('isShenHe').setValue(cate[0].isShenHe);
//				grids.getStore().add(catee);
//			},
//		});
		
		var fielmenu=new Ext.menu.Menu({
			items:[{text:'批号设定'},{text:'条码打印'}]
		});
		
		var arrs = [];
		var grids=Ext.create('Ext.grid.Panel',{
			//autoEncode:false,
			listeners:{
				containerdblclick:function(gridc,e,eOpts){
					gridc.getStore().add({'rownumberer':'','prodID':'','prdClassName':'','prodSize':'','unit':'','quantity':'','haveBatch':'','itemRemark':''});
				}
			},
			plugins:[
			        Ext.create('Ext.grid.plugin.CellEditing',{
			        	clicksToEdit:1
			        }) 
			        ],
			columns:[
				{header:'(栏号)',xtype:'rownumberer',dataIndex:'lh',width:50,sortable:false},
				{header:'物料编号',dataIndex:'prodID',width:100,editor:"textfield"},
				{header:'物料名称',dataIndex:'prdClassName',width:120,editor:"textfield"},
				{ header: '规格型号', dataIndex: 'prodSize', editor:"textfield"},
				{ header: '单位', dataIndex: 'unit' ,editor:"textfield"},
				{ header: '数量', dataIndex: 'quantity',editor:"textfield",},
				{ header: '批号', dataIndex: 'haveBatch',editor:"textfield" },
				{ header: '分录备注', dataIndex: 'itemRemark',editor:"textfield" }
			],
			id:'girdss',
			height:130,
			width:1971,
			autoScroll:false,
		});
		
		var filterPanel = Ext.create('Ext.panel.Panel',{
			bodyPadding:6,
			width:1985,
			height:170,
			items:[grids],
			bbar:[{xtype:"label",text:'总计',width:90},
			{xtype:"textfield",disabled:true,width:90,margin:'0 180',value:'0.00'},
			{xtype:"textfield",disabled:true,width:90,margin:'0',value:'0.00'},
			{xtype:"textfield",disabled:true,width:90,margin:'0 40 0 30',value:'0.00'},
			{xtype:"textfield",disabled:true,width:90,margin:'0 0 0 0',value:'0.00'}],
		});
		
		
		//中间
		var tableds=Ext.create('Ext.TabPanel',{
			width:"100%",
			height:230,
			autoScroll:true,
			bodyPadding:5,
			items:[{title:'内容',autoScroll:true,items:[filterPanel]},{title:'备注',xtype:'textarea',name:'Remark',fieldLabel: '备注',labelWidth: 30,}],
		});
		
		//尾部
		var formsg=Ext.create('Ext.form.Panel', {
	    bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[{
			xtype: 'textfield',
	        name: 'makerSign',
	        fieldLabel: '制单人员',
			style:'margin-left:20px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
	        id:'makerSign',
			},{
			style:'margin-left:20px',
			xtype: 'textfield',
	        name: 'permitterSign',
	        fieldLabel: '复核人员',
			style:'margin-left:19px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
	        id:'permitterSign',
			}],
		});
		
		//头部form表单
		var forms=Ext.create('Ext.form.Panel', {
    	bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[
		{
		style:'margin-left:20px;',
		xtype: 'combo',
        name: 'wareOutName',
        fieldLabel: '仓库调出',
		width:250,
        labelWidth: 80,
        anchor: '100%',
        id:'wareOutName',
        displayField:'s',
        valueField:'a',
        store:Ext.create('Ext.data.Store',{
        	fields:['a','s'],
        	data:[
        	      {"a":"1","s":"成品仓"},
        	      {"a":"2","s":"第一仓库"}
        	 ]
		}),
		typeAhead:true,
		mode:'local',
		triggerAction:'all',
		selectOnFocus:true,
		},{
		style:'margin-left:30px;color:blue',
		xtype: 'datefield',
        name: 'moveDate',
        fieldLabel: '单据日期',
        format:'Y-m-d',
        altFormats:'Y/m/d|Ymd',
		width:250,
        labelWidth: 70,
        anchor: '100%',
        id:'moveDate',
        listeners:{'blur':function(){danhao(); }}
		},{
		style:'margin-left:20px;',
		xtype: 'combo',
        name: 'wareName',
        fieldLabel: '仓库调入',
		width:250,
        labelWidth: 80,
        anchor: '100%',
        id:'wareName',
        displayField:'s',
        valueField:'a',
        store:Ext.create('Ext.data.Store',{
        	fields:['a','s'],
        	data:[
        	      {"a":"1","s":"成品仓"},
        	      {"a":"2","s":"第一仓库"}
        	 ]
		}),
		typeAhead:true,
		mode:'local',
		triggerAction:'all',
		selectOnFocus:true,
		},{
		style:'margin-left:30px;color:blue',
		xtype:'textfield',
		name:'moveNo',
		fieldLabel:'单据号码',
		width:250,
		labelWidth:70,
		anchor:'100%',
		id:'moveNo',
		},{
		xtype:'textfield',
		name:'isDel',
		fieldLabel:'是否删除',
		hidden: true, 
		hideLabel:true,
		id:'isDel',
		},{
		xtype:'textfield',
		name:'isShenHe',
		fieldLabel:'是否审核',
		hidden: true, 
		hideLabel:true,
		id:'isShenHe',
		},tableds,formsg]
    });
		
		//删除--逻辑删除（数据库中存在但是页面不显示）
		function update(){
			var temp={
				wareOutName:Ext.getCmp('wareOutName').getValue(),
				moveDate:Ext.getCmp('moveDate').getValue(),
				wareName:Ext.getCmp('wareName').getValue(),
				moveNo:Ext.getCmp('moveNo').getValue(),
				makerSign:Ext.getCmp('makerSign').getValue(),
				permitterSign:Ext.getCmp('permitterSign').getValue(),
				isDel:Ext.getCmp('isDel').getValue(),
				allo:Ext.pluck(grids.getStore().data.items,"data"),
			};
			Ext.Ajax.request({
				url:'http://localhost:8080/updateAllocate',
				headers:{"Content-Type":"application/json"},
				params:JSON.stringify(temp),
				success:function(response){
					Ext.MessageBox.alert("提示","已删除!!!");
				}
			});
		}
		
		
		//新增
		function add(){
			if(Ext.getCmp('wareOutName').getValue()==Ext.getCmp('wareName').getValue()){
				Ext.MessageBox.alert("提示","调入仓库和调出仓库不能相同！");
				return false;
			}
//			if(){
//				Ext.MessageBox.alert("提示","物料 C03-W-HP-1020D 数量不能等于0！");
//				return false;
//			}
//			var grid =Ext.getCmp("girdss").getStore();
			var temp={
					wareOutName:Ext.getCmp('wareOutName').getValue(),
					moveDate:Ext.getCmp('moveDate').getValue(),
					wareName:Ext.getCmp('wareName').getValue(),
					moveNo:Ext.getCmp('moveNo').getValue(),
					makerSign:Ext.getCmp('makerSign').getValue(),
					permitterSign:Ext.getCmp('permitterSign').getValue(),
					isDel:Ext.getCmp('isDel').getValue(),
					allo:Ext.pluck(grids.getStore().data.items,"data"),
			};
			Ext.Ajax.request({
				url:'http://localhost:8080/insertlyh',
				headers:{"Content-Type":"application/json"},
				params:JSON.stringify(temp),
				success:function(response){
					Ext.MessageBox.alert("提示","新增成功",function(){});
					store.reload();
				}
			});
		}
		
		
    	//窗体大小
		var windowst=new Ext.Window({
			width:620,
			height:410,
			title:"调拨单",
			closable:true,
			resizable:false, //设置是否可以改变大小
			draggable:true,
			anchor: '100%',
			items:[toolbar,forms],
//			listeners:{
//				activate:function(){
//					queryAllocateInfo();
//				}
//			},
			bbar:[{xtype:'splitbutton',text:'功能',width:90,menu:fielmenu}],
		});